$(function () {
    findAll();
});

function findAll() {
    let result = myAjax("/back/product/findAll", {});
    setData(result.list);
    console.log(result);
}

function setData(data) {
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += '<div>\n' +
            '            <div>' + data[i].id + '</div>\n' +
            '            <div>' + data[i].name + '</div>\n' +
            '            <div>' + toNull(data[i].price) + '</div>\n' +
            '            <div>' + toNull(data[i].normalPrice) + '</div>\n' +
            '            <div>' + toNull(data[i].content) + '</div>\n' +
            '            <div>' + (data[i].isShow == 1 ? '<lable class="nomal-color">正常</lable>' : '<lable class="exception-color">异常</lable>') + '</div>\n' +
            '            <div><img src="' + toNull(data[i].imgHref) + '" style="width: 30px;height: 30px" ></div>\n' +
            '            <div>' + toNull(data[i].cuisineName) + '</div>\n' +
            '            <div>' +
            '                   <div title="编辑" onclick="toEditPage(' + data[i].id + ')"><i class="iconfont">&#xe626;</i></div>' +
            '                   <div title="删除" onclick="del(' + data[i].id + ')"><i class="iconfont">&#xe624;</i></div>' +
            '            </div>\n' +
            '        </div>';
    }
    $("#tbody").html(html);
}
function returnContent(value) {
    return value.replace("/faddafs/","");
}
function toEditPage(id) {
    sessionStorage.setItem("productId", id);
    load("/product/productEdit.html");
}

function del(id) {
    let result = myAjax("/back/product/del", {id: id});
    if (result.result == "success") {
        findAll();
    } else {
        alert("error")
    }
}

//将现在在页面上的null或者undefined，转换为空“”
function toNull(value) {
    return value == "null" || value == undefined ? "" : value;
}